<template>
    <div>
        <el-card class="!border-none" shadow="never">
            <el-form ref="formRef" class="mb-[-16px]" :model="queryParams" :inline="true">
                <el-form-item label="用户ID">
                    <el-input
                            class="w-[150px]"
                            v-model="queryParams.uuid"
                            placeholder="请输入用户ID"
                            clearable
                            @keyup.enter="resetPage"
                    />
                </el-form-item>
                <el-form-item label="用户昵称/姓名/手机号">
                    <el-input
                            class="w-[280px]"
                            v-model="queryParams.user_keyword"
                            placeholder="请输入用户昵称/姓名/手机号"
                            clearable
                            @keyup.enter="resetPage"
                    />
                </el-form-item>
                <el-form-item label="团长ID搜索">
                    <el-input
                            class="w-[280px]"
                            v-model="queryParams.community_user_id"
                            placeholder="请输入团长ID"
                            clearable
                            @keyup.enter="resetPage"
                    />
                </el-form-item>
                <el-form-item label="团长手机号/昵称搜索">
                    <el-input
                            class="w-[280px]"
                            v-model="queryParams.community_keyword"
                            placeholder="请输入团长ID"
                            clearable
                            @keyup.enter="resetPage"
                    />
                </el-form-item>
				<el-form-item label="直播间ID">
				    <el-input
				            class="w-[150px]"
				            v-model="queryParams.room_id"
				            placeholder="请输入直播间ID"
				            clearable
				            @keyup.enter="resetPage"
				    />
				</el-form-item>
				<el-form-item label="积分发放状态">
				    <el-select class="w-[200px]" v-model="queryParams.sign_red" clearable>
				       <el-option value="1" label="已发放">已发放</el-option>
					   <el-option value="2" label="未发放">未发放</el-option>
				    </el-select>
				</el-form-item>

                <el-form-item label="领取时间">
                    <daterange-picker
                        v-model:startTime="queryParams.start_time"
                        v-model:endTime="queryParams.end_time"
                    />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="resetPage">查询</el-button>
                    <el-button @click="resetParams">重置</el-button>
                </el-form-item>
            </el-form>
        </el-card>
        <el-card class="!border-none mt-4" shadow="never">
			<div class="flex justify-end">
			    <el-button @click="handleAdd" type="primary" class="w-[120px] h-[30px] mb-[9px] text-[12px]">直播间补发奖励</el-button>
				<el-button @click="handleSign" type="primary" class="w-[90px] h-[30px] mb-[9px] text-[12px]">累计签到设置</el-button>
			</div>
            <el-tabs class="demo-tabs">
                <el-table size="large" v-loading="pager.loading" :data="pager.lists" style="width: 100%">
                    <el-table-column label="用户ID / 手机号 / 昵称" prop="name" min-width="220">
                        <template #default="{ row }">
                            {{ row.uuid }} / {{ row.phone }} / {{ row.nickname }}
                        </template>
                    </el-table-column>
                    <el-table-column label="团长ID / 手机号 / 昵称" prop="name"  min-width="220">
                        <template #default="{ row }">
                            {{ row.community_uuid }} / {{ row.community_phone }} / {{ row.community_name }}
                        </template>
                    </el-table-column>
                    <el-table-column label="直播房间号" prop="room_id"  min-width="120" />
                    <el-table-column label="观看时长 / 秒" prop="name"  min-width="150">
                         <template #default="{ row }">
                            {{ row.time }}
                        </template>
                    </el-table-column>
                    <el-table-column label="签到礼品券" prop="reward"  min-width="150" />
                    <el-table-column label="签到积分金额" prop="sign_red"  min-width="150" />
                   <!-- <el-table-column label="备注" prop="name"  min-width="150">
                         <template #default="{ row }">
                            {{ row.created_at }}
                        </template>
                    </el-table-column> -->
					<el-table-column label="签到时间" prop="created_at"  min-width="190" />

                    <el-table-column label="操作面板" min-width="160" fixed="right">
                        <template #default="{ row }">
                            <el-button type="primary" link @click="userDelete(row.room_id)" v-if="row.is_red==2">
                                补发积分
                            </el-button>
                        </template>

                    </el-table-column>
                </el-table>
                <div class="flex justify-end mt-4">
                    <pagination v-model="pager" @change="getLists" />
                </div>
            </el-tabs>
        </el-card>
		<edit-popup v-if="showEdit" ref="editRef" @success="getLists" @close="showEdit = false" />
		<signPopup v-if="showSign" ref="signRef" @success="getLists" @close="showSign = false" />
    </div>
</template>
<script lang="ts" setup>
    import { reissue, signLogList } from '@/api/consumer'
    import { usePaging } from '@/hooks/usePaging'
    import feedback from "@/utils/feedback";
    import EditPopup from './component/reissue.vue'
	import signPopup from './component/sign.vue'
    const queryParams = reactive({
        uuid: '',
        user_keyword: '',
        community_user_id: '',
        community_keyword: '',
        start_time: '',
        end_time: '',
		room_id:'',
		sign_red:''
    });

    const { pager, getLists, resetPage, resetParams } = usePaging({
        fetchFun: signLogList,
        params: queryParams
    });
	const editRef = shallowRef<InstanceType<typeof EditPopup>>()
	const showEdit = ref(false)
	const handleAdd = async () => {
	    showEdit.value = true
	    await nextTick()
	    editRef.value?.open()
	}
	const signRef = shallowRef<InstanceType<typeof signPopup>>()
	const showSign = ref(false)
	const handleSign = async () => {
	    showSign.value = true
	    await nextTick()
	    signRef.value?.open()
	}
    getLists();
	let price:any = []
    // 补发
    const userDelete = async (id: number) => {
     price = await feedback.prompt("请输入补发积分金额","补发积分");
	 console.log(price)
	 if(price.action=="confirm"){
		 reissue({log_id: id,reissue_price:price.value});
		 getLists()
	 }

    };

</script>
